package ali.pathresolver;

import ali.action.Speed;
import ali.compass.Compass;
import ali.point.Point;

import static ali.point.Point.point;
import static java.lang.Math.cos;
import static java.lang.StrictMath.sin;

/**
 * Created by IntelliJ IDEA.
 * User: aliolci
 * Date: 04/06/11
 * Time: 08:50
 * To change this template use File | Settings | File Templates.
 */
public class SinglePathResolver{
    private Point source;
    private Point destination;
    private Speed speed;
    private Compass compass;
    private boolean hasNext;

    public SinglePathResolver(Point source, Point destination, Speed speed) {
        this.source=source;
        this.destination=destination;
        this.speed=speed;
        this.compass = Compass.getCompass(source, destination);
        hasNext=true;
    }

    public Point getNextLocation(){
        hasNextCheck();
        Double incline = source.getInclineBetweenThisPointAnd(destination);
        float newX= (float) ((compass.getHorizontalDirectionMathSign()*(cos(incline)*speed.getPixelPerTimeTick())) + source.getX());
        float newY= (float) ((compass.getVerticalDirectionMathSign()*(sin(incline)*speed.getPixelPerTimeTick())) + source.getY());
        source = point(newX, newY);
        return source;
    }

    public boolean hasNext(){
        return hasNext;
    }

    private void hasNextCheck() {
        if(source.equals(destination)){
            hasNext=false;
        }
    }

    public Compass getCompass() {
        return compass;
    }
}
